package com.jiukuaidao.zhulin.module.user;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiukuaidao.library.base.BaseActivity;
import com.jiukuaidao.library.util.ImageGlideUtils;
import com.jiukuaidao.zhulin.AppContext;
import com.jiukuaidao.zhulin.R;
import com.jiukuaidao.zhulin.data.TaskProvider;
import com.jiukuaidao.zhulin.module.user.contract.UserInfoContract;
import com.jiukuaidao.zhulin.module.user.presenter.UserInfoPresenter;

import butterknife.BindView;

/**
 * Author : PaiTaSuo
 * Date : 2016/5/26
 * Description : 用户
 */
public class UserInfoActivity extends BaseActivity<UserInfoContract.Presenter> implements View.OnClickListener, UserInfoContract.View {
    @BindView(R.id.titile_left_imageview)
    ImageView mLeftImg;
    @BindView(R.id.titile_text)
    TextView mTitileText;
    @BindView(R.id.titile_right_text)
    TextView mTitileRightText;
    @BindView(R.id.rl_update_password)
    RelativeLayout mRlPsw;
    @BindView(R.id.iv_user_head)
    ImageView mIvHeader;
    @BindView(R.id.tv_username)
    TextView mUserName;
    @BindView(R.id.tv_password)
    TextView mSetPsw;
    private String mPhone;
    private String mHeaderIcon;
    private int mIsSetpass;

    @Override
    protected View getTargetView() {
        return null;
    }


    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_user_info;
    }

    @Override
    protected void handleBundle(Bundle bundle) {
        mPhone = bundle.getString("phone", "");
        mHeaderIcon = bundle.getString("headerIcon", "");
        mIsSetpass = bundle.getInt("isSetpass", -1);
    }

    @Override
    protected void init() {
        mTitileText.setText(R.string.user_info);
        new UserInfoPresenter(TaskProvider.provideTasksRepository(this), this);
        setOnClickListener();
        mUserName.setText(mPhone);
        ImageGlideUtils.CircleGlideImages(this, mHeaderIcon, mIvHeader, R.mipmap.ic_user_info);
        if (mIsSetpass == 0) {
            mSetPsw.setText(AppContext.getContext().getString(R.string.password_set));
        }
        if (mIsSetpass == 1) {
            mSetPsw.setText(AppContext.getContext().getString(R.string.password_update));
        }
    }


    @Override
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.rl_update_password:
                if (mIsSetpass == 0) {
                    intentJump(SetPasswordActivity.class);
                }
                if (mIsSetpass == 1) {
                    bundle.putString("phone", mPhone);
                    intentJump(UpdatePasswordActivity.class, bundle);
                }
                break;
            case R.id.titile_left_imageview:
                finish();
                break;


        }
    }

    public void setOnClickListener() {
        mRlPsw.setOnClickListener(this);
        mLeftImg.setOnClickListener(this);
    }
}
